export default defineNuxtPlugin((nuxtApp) => {
    const router = nuxtApp.$router;
    router.options.scrollBehavior = (to, from, savedPosition) => {
        if (savedPosition) {
            return savedPosition;
        } else if (to.hash) {
            return {
                el: to.hash, // 滚动到锚点
                behavior: "smooth",
            };
        } else {
            return { top: 0, behavior: "smooth" };
        }
    };
    router.afterEach((to, from) => {
        const headerEle = document.querySelector(".header-wrapper");
        const headerHeight = headerEle.offsetHeight;
        const menuEle = document.querySelector(".page_banner-menu");
        const offsetTop = menuEle?.getBoundingClientRect().top;
        if (to.name === from.name && to.name !== "about") {
            setTimeout(() => {
                if (window.scrollY > offsetTop - headerHeight) {
                    window.scrollTo({
                        top: 800,
                        behavior: "smooth",
                    });
                    console.log(
                        "页面滚动距离--->",
                        window.scrollY,
                        offsetTop,
                        headerHeight
                    );
                }
            }, 1);
        }
    });
});
